package hn.cch.advanced.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

public class ExecutorServiceUtil {

    /**
     * 等待线程池里所有任务执行完毕
     *
     * @param threadPool
     */
    public static void complete(ExecutorService threadPool) {
        try {
            boolean flag = false;
            do {
                flag = threadPool.awaitTermination(1, TimeUnit.SECONDS);
            } while (!flag);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
